package tls;




import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;


import java.security.*;
import java.security.spec.ECGenParameterSpec;

public class ECDHEUtill {

    public static void main(String[] args) throws DecoderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {

        String clientRandom="9c8ac2cd2f8215cfe52fad5793654d6e6777a5df2338dce64dea6fc6cdcb7428";

        String serverRandom="972c84e82df3d560a90be7b4fe928fb42dd287e20aa0b74c12b76fba67410c52";

        byte[] bytes = Hex.decodeHex(clientRandom);
        System.out.println(bytes.length);



        String randomString=clientRandom+serverRandom;

        SecureRandom random=new SecureRandom(Hex.decodeHex(randomString));

        String curveName = "secp256r1";
        ECGenParameterSpec ecSpec = new ECGenParameterSpec(curveName);
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC");
        keyPairGenerator.initialize(ecSpec, random);
        KeyPair keyPair = keyPairGenerator.generateKeyPair();
        System.err.println("Private Key: " + keyPair.getPrivate());
        System.err.println("Public Key: " + Hex.encodeHexString(keyPair.getPublic().getEncoded()));
        System.err.println("Public Key: " + keyPair.getPublic().getEncoded().length);

        MessageDigest instance = MessageDigest.getInstance("SHA-256");
        System.err.println(Hex.encodeHexString(instance.digest(keyPair.getPublic().getEncoded())));

        System.out.println("3059301306072a8648ce3d020106082a8648ce3d0301070342000477308e5ce82713f362a0e9bc39c477cc6cb4b6256fba5104285283dd1ac0d50d46e93e98b7951a8097f0bdaf2553761c828b14c98e07159ece47066c6d21019f".length());
        ;


    }
}
